<?php


/**
 * @author Garry
 *
 *
 */
class Image extends HtmlDisplay {
	//TODO - Insert your code here
	

	public function __construct( $path,$maxsize=null,$originalwidth=null,$height=0) {
		parent::__construct();
		$this->dat = $this->HtmlElement('img');
		$width;
		if( !empty($maxsize)){
			$controller = CI_Controller::get_instance();
			$controller->load->helper('Image_helper');
			if( $originalwidth >= $height && $originalwidth > $maxsize  ){
				$ratio = $originalwidth/$height;
				$height = round($maxsize/$ratio);
				$width = $maxsize;
				$path = resizeImage( $path,$width,$height );
			}
			else if( $height > $originalwidth && $height > $maxsize ){
				$ratio = $height/$originalwidth;
				$width = round($maxsize/$ratio);
				$height = $maxsize;
				$path = resizeImage( $path,$width,$maxsize );
			}
			$this->dat->addAttribute('width',$width);
			$this->dat->addAttribute('height',$height);		
		}
		$this->dat->addAttribute('src',$path);
	}
	/**
	 *
	 */
	function __destruct() {

		//TODO - Insert your code here
	}
	
	public function finalize(){
		$this->output = new stdClass();
		$this->output->imgs = (string)$this->dat->asXML();
	}
	
}


?>